package com.briup.day19;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author ThinkBook
 */
public class Test05_Map {
    public static void main(String[] args) {

        //1.实例化map对象
        Map<Integer,String> map = new HashMap<>();

        //2.往map添加元素[key-value]键值对
        map.put(4,"tom");
        map.put(2,"lucy");
        map.put(1,"lucy");
        map.put(3,"rose");
        map.put(1,"cuihua");

        System.out.println("size: " + map.size());
        System.out.println("isEmpty: " + map.isEmpty());

        //3.遍历map集合
        // 第一种：先获取所有的key，遍历key(根据key进一步获取value)
        Set<Integer> set = map.keySet();
        for (Integer k : set) {
            //根据key 获取 value
            String v = map.get(k);
            System.out.println(k + ": " + v);
        }

        //System.out.println(map);
    }
}
